export function arraySpan(data, key) {
  const spanArr = [];
  let position = 0;
  data?.forEach((item, index) => {
    if (index === 0) {
      spanArr.push(1);
      position = 0;
    } else {
      if (item[key] === data[index - 1][key]) {
        spanArr[position] += 1;
        spanArr.push(0);
      } else {
        position = index;
        spanArr.push(1);
      }
    }
  });
  return spanArr;
}
export const setCustomCell = (
  rowHoverProcInsId,
  rowProcInsId,
  span = false
) => {
  if (span) {
    return (record, rowIndex) => {
      return {
        style: {
          backgroundColor:
            record.procInsId === rowHoverProcInsId.value ? "#f0f0f0" : "",
        },
        on: {
          mouseenter: () => {
            // rowHoverProcInsId.value = record.procInsId;
            rowProcInsId.value = record.procInsId;
          },
          mouseleave: () => {
            // rowHoverProcInsId.value = "";
            rowProcInsId.value = "";
          },
        },
      };
    };
  }
  return (record, rowIndex) => {
    return {
      on: {
        mouseenter: () => {
          rowHoverProcInsId.value = record.procInsId;
        },
        /*mouseleave: () => {
          // rowHoverProcInsId.value = "";
        },*/
      },
    };
  };
};
export const setTableBind = (rowProcInsId, emit) => {
  return {
    rowClassName: (record) => {
      return record.procInsId === rowProcInsId.value ? "hover" : "";
    },
    customRow: (record) => {
      return {
        on: {
          mouseenter: () => {
            emit("setRowHoverProcInsId", record.procInsId);
          },
          mouseleave: () => {
            emit("setRowHoverProcInsId", "");
          },
        },
      };
    },
  };
};
